package com.hr.controller;


import com.hr.entity.Faq;
import com.hr.service.FaqService;
import com.hr.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hr
 * @since 2021-10-25
 */
@CrossOrigin
@RestController
@RequestMapping("/hr/service/faq")
public class FaqController {

    @Autowired
    FaqService faqService;

    @GetMapping("faqs")
    public R get_faqs(){
        List<Faq> faqs = faqService.list(null);
        return R.ok().data("faqs", faqs);
    }


    @GetMapping("faq")
    public R get_faq(String id) {
        Faq faq = faqService.getById(id);
        return R.ok().data("faq", faq);
    }

    @PostMapping("faq")
    public R add_faq(@RequestBody Faq faq) {
        boolean save = faqService.save(faq);
        return save ? R.ok() : R.error();
    }

    @PutMapping("faq")
    public R update_faq(@RequestBody Faq faq) {
        boolean update = faqService.updateById(faq);
        return update ? R.ok() : R.error();
    }

    @DeleteMapping("faq/{id}")
    public R delete_faq(@PathVariable("id") Integer id) {
        boolean delete = faqService.removeById(id);
        return delete ? R.ok() : R.error();
    }

}

